package com.hhf.rpa.job.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhf.rpa.job.entity.BaseJobLog;
import com.hhf.rpa.job.mapper.BaseJobLogMapper;
import com.hhf.rpa.job.pojo.form.BaseJobForm;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BaseJobLogServiceImpl extends ServiceImpl<BaseJobLogMapper, BaseJobLog> implements BaseJobLogService {
    @Override
    public BaseJobLog getJobLogByLogId(Long logId) {
        QueryWrapper<BaseJobLog> qw = new QueryWrapper<>();
        qw.eq("log_id", logId);
        List<BaseJobLog> list = list(qw);
        if(list != null && list.size()>0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public Page<BaseJobLog> getJobLogPage(BaseJobForm form) {
        Page<BaseJobLog> page = new Page<>(form.getCurrent(), form.getSize());
        OrderItem orderItem= OrderItem.desc("log_id");
        ArrayList<OrderItem> orders = new ArrayList<>();
        orders.add(orderItem);
        page.setOrders(orders);
        return baseMapper.getJobLogPage(page, form.getJobId());
    }
}
